import axios from 'axios'

export const BatchesOfInventoryService = class BatchesOfInventoryService {
    static batchesOfInventoryService = null
    requestUrl = '/purchase/batchesOfInventories'

    static getInstance() {
        if (this.batchesOfInventoryService == null) {
            this.batchesOfInventoryService = new BatchesOfInventoryService()
        }
        return this.batchesOfInventoryService
    }

    /**
     * 获取最大采购单号的方法
     */
    renderCode() {
        return axios.get(`${this.requestUrl}/code`)
    }

    /**
     * 直接入库的方法
     */
    wareHousingBatchesOfInventory(batchesOfInventory, purchases) {
        const params = {}
        params.batchesOfInventory = batchesOfInventory
        params.purchases = purchases
        return axios.post(this.requestUrl, params)
    }

    /**
     * 提交审核的方法
     */
    submitBatchesOfInventory(batchesOfInventory, purchases) {
        const params = {}
        params.batchesOfInventory = batchesOfInventory
        params.purchases = purchases
        return axios.post(`${this.requestUrl}/submit`, params)
    }

    /**
     * 查询审批单的方法
     * @param params
     * @returns {Promise<AxiosResponse<T>>}
     */
    getForms(params) {
        return axios.get(`${this.requestUrl}/forms`, {
            params
        })
    }

    /**
     * 提交详情
     * @param formAudit
     */
    submitAudit(formAudit) {
        return axios.post(`${this.requestUrl}/audit`, formAudit)
    }

    /**
     * 获取源表数据和结构
     * @param fid
     */
    getColumnsAndValues(fid) {
        return axios.get(`${this.requestUrl}/target/${fid}`)
    }

    /**
     * 移除审批单
     * @param fid
     */
    removeForm(fid) {
        return axios.delete(`${this.requestUrl}/form/${fid}`)
    }
}
